package com.code.zjm.demo.ui;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

/**
 * Created by ZJM on 2017/3/4.
 */
public class AtyShowNeonEffect extends AppCompatActivity implements Runnable {
    //5个TextView的值
    private int[] colors = new int[]{0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFF00FF, 0xFF00FFFF};
    private int[] nextViewPoints = new int[]{1, 2, 3, 4, 0};
    private View[] views;
    private int currentViewPoint = 0;//当前的View
    private Handler handler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_neno);
        views = new View[]{findViewById(R.id.tv1), findViewById(R.id.tv2), findViewById(R.id.tv3),
                findViewById(R.id.tv4), findViewById(R.id.tv5)};
        handler = new Handler();
        handler.postDelayed(this, 1000);

    }

    @Override
    public void run() {
        int nextViewPoint = currentViewPoint;
        for (int i = views.length - 1; i >= 0; i--) {
            //设置当前TextView的背景颜色
            views[i].setBackgroundColor(colors[nextViewPoints[nextViewPoint]]);
            //获取下一个TextView的背景颜色值得索引
            nextViewPoint = nextViewPoints[nextViewPoint];
        }
        currentViewPoint++;
        if (currentViewPoint == 5)
            currentViewPoint = 0;
        handler.postDelayed(this, 1000);//每300毫秒循环一次
    }
}
